package com.shioirikukuri.mapper;

import com.shioirikukuri.entity.UserMember;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMemberMapper {
	// 插入一条会员记录
	@Insert("INSERT INTO user_member (user_id, level_id, total_points, balance, created_at) " +
			"VALUES (#{userId}, #{levelId}, #{totalPoints}, #{balance}, NOW())")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	void insertUserMember(UserMember userMember);

	// 根据ID查询会员信息
	@Select("SELECT * FROM user_member WHERE id = #{id}")
	UserMember selectUserMemberById(Long id);

	// 根据用户ID查询会员信息
	@Select("SELECT * FROM user_member WHERE user_id = #{userId}")
	UserMember selectUserMemberByUserId(Long userId);

	// 查询所有会员信息
	@Select("SELECT * FROM user_member")
	List<UserMember> selectAllUserMembers();

	// 更新会员信息
	@Update("UPDATE user_member SET user_id = #{userId}, level_id = #{levelId}, total_points = #{totalPoints}, " +
			"balance = #{balance} WHERE id = #{id}")
	void updateUserMember(UserMember userMember);

	// 根据ID删除会员信息
	@Delete("DELETE FROM user_member WHERE id = #{id}")
	void deleteUserMemberById(Long id);

	@Select("SELECT * FROM user_member WHERE level_id = #{memberLevelId}")
	List<UserMember> selectByMemberLevelId(Long memberLevelId);

}
